# get_index.py
import json
import requests

def get_index() -> requests.Response:
    # 1. 固定 URL
    url = 'https://api.xd.com/games/play?app=sxd&server=s3301'
    # 2. 固定 headers
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7,en-US;q=0.6',
        'Cache-Control': 'max-age=0',
        'Connection': 'keep-alive',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0',
    }
    # 3. 读取 cookie.json
    with open('cookie.json', 'r', encoding='utf-8') as f:
        cookie_list = json.load(f)
    cookies = {c['name']: c['value'] for c in cookie_list}
    # 4. 发请求并返回
    return requests.get(url, headers=headers, cookies=cookies, timeout=10)

# ---------------- 测试 ----------------
if __name__ == '__main__':
    resp = get_index()
    print(resp.status_code)
    print(resp)


